package com.livegoods.dao.impl;

import com.livegoods.dao.HouseDao4MongoDB;
import com.livegoods.pojo.House;
import com.mongodb.client.result.UpdateResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;

@Repository
public class HouseDao4MongoDBImpl implements HouseDao4MongoDB {

    @Autowired
    private MongoTemplate mongoTemplate;

    public long update(String houseId) {


        Criteria criteria = Criteria.where("id").is(houseId);

        Query query = new Query(criteria);


        Update update = new Update();
        update.set("isRent",false);

        UpdateResult updateResult = mongoTemplate.updateFirst(query, update, House.class);

        long modifiedCount = updateResult.getModifiedCount();


        return modifiedCount;
    }
}
